infos = [
    {
        "first_title": "概述",
        "sec_title": "项目概况",
        "third_title": "项目全称及简称",
        "content": "介绍项目的全称和简称，明确项目的标识和称呼。",
        "num": "100"
    },
    {
        "first_title": "概述",
        "sec_title": "项目概况",
        "third_title": "建设目标和任务",
        "content": "阐述项目的建设目标和主要任务，明确项目的核心目的。",
        "num": "150"
    }
]


def main(title_infos: list) -> dict:
    # 构建层级结构
    hierarchy = {}
    for item in title_infos:
        first = item.get("first_title", "")
        sec = item.get("sec_title", "")
        if first not in hierarchy:
            hierarchy[first] = {}
        if sec not in hierarchy[first]:
            hierarchy[first][sec] = []
        hierarchy[first][sec].append(item)

    # 生成大纲字符串
    outline = []
    for first_title, sec_dict in hierarchy.items():
        outline.append(f"# {first_title}")
        for sec_title, third_titles in sec_dict.items():
            outline.append(f"## {sec_title}")
            for it in third_titles:
                third = it.get("third_title", "")
                content = it.get("content", "")
                num = it.get("num", "")
                outline.append(f"### {third}")
                outline.append(f"写作思路：{content}，字数：{num}")

    result = "\n".join(outline)
    return {
        "result": result
    }


print(main(infos))
